package containerlogistik.implementation;

import static containerlogistik.implementation.Values.*;
import containerlogistik.interfaces.Force;
import containerlogistik.interfaces.Power;
import containerlogistik.interfaces.Speed;

public class PowerInKw extends AbstractValue<Power> implements Power {

    private final double kilowatt;
    
    private PowerInKw(double kilowatt) {
        this.kilowatt = kilowatt;
    }

    static Power valueOf(double kw) {
        return new PowerInKw(kw);
    }

    @Override
    public double kw() {
        return this.kilowatt;
    }

    @Override
    public double w() {
        return this.kw() * KW_IN_W;
    }

    @Override
    public double mw() {        
        return this.kw() * KW_IN_MW;
    }

    @Override
    public boolean isZero() {
        return (this.equals(ZERO_POWER));
    }

    @Override
    public boolean isValid() {
        return true;
    }

    @Override
    public String toString() {
        return "PowerInKw{" + "kw=" + this.kw() + ", w=" + this.w() + 
                ", mw=" + this.mw() +  '}';
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final PowerInKw other = (PowerInKw) obj;
        if (Double.doubleToLongBits(this.kw()) != Double.doubleToLongBits(other.kw())) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        return hashDouble(this.kw());
    }

    @Override
    public int compareTo(Power o) {
        return Double.compare(this.kw(), o.kw());
    }

    @Override
    public Power add(Power value) {
        return powerInKw(this.kw() + value.kw());
    }

    @Override
    public Power sub(Power value) {
        return powerInKw(this.kw() - value.kw());
    }

    @Override
    public Power mul(double factor) {
        return powerInKw(this.kw() * factor);
    }

    @Override
    public Power div(double factor) {
        return powerInKw(this.kw() / factor);
    }

    @Override
    public Power inverse() {
        return powerInKw(-this.kw());
    }

    @Override
    public double div(Power value) {
        return (this.kw() / value.kw());
    }

    @Override
    public Force div(Speed value) {
        return forceInN(this.kw() / Math.abs(value.ms()));
    }
}
